<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="keywords" content="">
<meta name="description" content="">
<meta name="author" content="">
<title></title>
<!--    <link href="assets/css/icons.css" rel="stylesheet"> -->
<!-- <link href="assets/css/bootstrap.min.css" rel="stylesheet"> -->
<link href="assets/css/style.css" rel="stylesheet">
<!--     <link href="assets/css/responsive.css" rel="stylesheet"> -->

</head>
<body>

	<form id="deptForm">
		<h2 class="header-title text-center" id="title">添加奖惩信息</h2>
		<div class="form-group">
			<input id="deptName" name="deptName" type="text" class="form-control"
				placeholder="部门名称">
		</div>
		<div class="form-group">
			<input id="deptTime" name="deptTime" type="text" class="form-control"
				placeholder="创建时间">
		</div>
		<div class="form-group">
			<input id="deptNum" name="deptNum" type="text" class="form-control" placeholder="人数">
		</div>
		<div class="form-group">
			<input id="remark" name="remark" type="text" class="form-control" placeholder="备注">
		</div>
		<div class="form-group">
			<input type="button" id="confirmDept" value="确定"
				class="btn btn-primary btn-block"> <input type="button"
				id="returnDept" value="返回" class="btn btn-primary btn-block">
		</div>
	</form>

	<script>
		$(function(){
			$("#title").html("修改部门信息");
			//截取参数
			var id = deptId;
			if(id!=null){
				
				$.ajax({
					type : "get",
					url : "/HMS/queryDeptInfoById",
					dataType : 'json',
					data:{"id":id},
					contentType : "application/json;charset=UTF-8",
					success : function(obj) {
						$("#deptName").val(obj.Obj.data[0].departmentName);
						$("#deptTime").val(new Date(obj.Obj.data[0].createTime).toLocaleString());
						$("#deptNum").val(obj.Obj.data[0].personNum);
						$("#remark").val(obj.Obj.data[0].remark);
					},
					error : function(data) {
						alert('连接失败');
					}
				});
			}
			
			
			//确认按钮
			

			$("#confirmDept").click(function(){
				//数据校验
				checkDeptData();
				//启动校验
				$('#deptForm').bootstrapValidator('validate');
				
				if(!$('#deptForm').data('bootstrapValidator').isValid()){
					return;
				}
				//添加新的部门
				$.ajax({
					type : "get",
					url : "/HMS/addDeptInfo",
					dataType : 'json',
					data:{
						"id":id,
						"departmentName":$("#deptName").val(),
						"createTime":new Date($("#deptTime").val()),
						"personNum":$("#deptNum").val(),
						"remark":$("#remark").val(),},
					contentType : "application/json;charset=UTF-8",
					success : function(value) {
						if(value.success == "OK"){
// 							addTable();
							alert("操作成功");
							
						}else{
							//登陆失败
							alert(value.msg);
						}
					},
					error : function(data) {
						alert("网络异常，请稍后重试");
					}
				});
			});
			//返回按钮
			$("#returnDept").click(function(){
				initDept();
			});
			
			
		});
		
		function checkDeptData(){
			$('#deptForm').bootstrapValidator({
			　     message: '输入值错误，请重新输入',
			   feedbackIcons:{
				   validating : 'glyphicon glyphicon-refresh'
			   },
			   fields: {
			     deptName : {
			          message: '用户名验证失败',
			          validators: {
			               notEmpty: {
			                     message: '用户名不能为空'
			               },
			               stringLength: {
			                     min: 1,
			                     max: 18,
			                     message: '用户名长度必须在1到18位之间'
			               }
			          }
			       },
			   deptTime : {
			          message: '用户名验证失败',
			          validators: {
			               notEmpty: {
			                     message: '用户名不能为空'
			               }
			          }
			       },
			       deptNum : {
				          message: '用户名验证失败',
				          validators: {
				               notEmpty: {
				                     message: '部门数量不能为空'
				               },
				               regexp: {
		                            regexp: /^\d+$/,
		                            message: '部门数量只能为正整数'
		                       }
				          }
				       },
			       remark : {
				          message: '用户名验证失败',
				          validators: {
				        	  stringLength: {
				                     max: 255,
				                     message: '备注超长'
				               }
				          }
				       }
			   
			   
			    }
		    });
		}
	</script>
</body>

</html>
